<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>PlayerScripts Live MW Stat Check</title>
    <script src="jquery-1.4.2.min.js"></script>
<script>
var EpackETA;
var MpackETA;
function createTab(link){
  chrome.tabs.create({url:link});
}

function GetStats(){
	var update_url = "http://toolbar.zynga.com/game_stats_proxy.php?src=mw";
	$.ajax({type: "GET",
		url: update_url,
		dataType: "json",
		success: function (msg){
			if(msg.error == true){
				$('#CurSta').css("display","none");
				$('#EpMpMWAP').css("display","none");
				$('#Synch').css("display","inline");
				return;
			}
			else{
				$('#CurSta').css("display","");
				$('#EpMpMWAP').css("display","");
				$('#Synch').css("display","none");
			}
			$('#user_health').html(msg.user_health);
			$('#user_energy').html(msg.user_energy);
			$('#user_stamina').html(msg.user_stamina);
			EpackETA = msg.energy_timestamp;
			MpackETA = msg.toolbar_energy_timestamp;
			setInterval(EpackChk,1000);
		}
	});
}

function EpackChk(){
	$('#epack').html(EpackT(EpackETA,"big"));
	$('#minipack').html(EpackT(MpackETA,"mini"));
}

function EpackT(unixts,pack_type){
	var now = Math.floor((new Date().getTime())/1000);
	var diff = now - unixts;
	if(pack_type == "big"){
		diff = 82800 - diff;
	}
	else{
		diff = 28800 - diff;
	}
	var seconds = diff % 60;
	if(seconds < 0){
		return "Ready";
	}
	if(seconds < 10){
		seconds = "0"+seconds;
	}
	diff = Math.floor(diff / 60);
	var minutes = diff%60;
	if(minutes < 0){
		return "Ready";
	}
	if(minutes < 10){
		minutes = "0"+minutes;
	}
	diff = Math.floor(diff/60);
	var hours = diff%60;
	if(hours < 0){
		return "Ready";
	}
	if(hours < 10){
		hours = "0"+hours;
	}
	return (hours+":"+minutes+":"+seconds);
}

function Synch(){
	var login_frame = document.createElement("iframe");
	login_frame.src="http://toolbar.zynga.com/game_iframe_proxy.php";
	login_frame.id="login_frame";
	login_frame.style.display="none";
	var logindiv = document.getElementById('logindiv');
	logindiv.insertBefore(login_frame,logindiv.firstChild);
	setTimeout(function(){logindiv.removeChild(login_frame);logindiv.insertBefore(login_frame,logindiv.firstChild);},2000);
	setTimeout(function(){logindiv.removeChild(login_frame);GetStats();},2500);
}

</script>
    <style>
	a{
		text-decoration:none
	}
</style>
</head>
<body background="http://www.playerscripts.com/images/mwap_graphics/MWAP_RT_STATS/grad.png" style="color:black; font-family:Verdana" onload="setTimeout(GetStats,10)">
<div id="logindiv"></div>
<table>
<tr>
<th colspan="5">
    <a href="#" onclick="createTab('http://www.playerscripts.com')"><img src="http://www.playerscripts.com/images/mwap_graphics/MWAP_RT_STATS/pslogo.png" /></a>
</th>
</tr>

<tr id="EpMpMWAP">
<td>
<img title ="ETA until next available energypack, click to claim" src="http://www.playerscripts.com/images/mwap_graphics/MWAP_RT_STATS/i.png" style="width:16px; height:16px" />&nbsp;&nbsp;<span id="epack" style="color:#000000;"></span>
</td>
<td>
<a href="#" onclick="createTab('http://toolbar.zynga.com/click.php?to=mwgamestatsplaynow')"><img title="ETA unitl next available minipack, click to claim" src="http://www.playerscripts.com/images/mwap_graphics/MWAP_RT_STATS/i.png" style="width:16px; height:16px" />&nbsp;&nbsp;<span id="minipack" style="color:#000000;"></span></a>
</td>
<td>
<div align="right"><a href="#" onclick="createTab('http://apps.facebook.com/inthemafia/')"><img title="Play Mafia Wars!" src="http://www.playerscripts.com/images/mwap_graphics/MWAP_RT_STATS/mwap-ico.png"/></a></div>
</td>
</tr>


<tr id="CurSta">
<tr>
&nbsp;&nbsp;&nbsp;<img title="Current Health" src="http://www.playerscripts.com/images/mwap_graphics/MWAP_RT_STATS/health.gif"><span id="user_health"></span>
</tr>
<tr>
&nbsp;&nbsp;&nbsp;<img title="Current Energy" src="http://www.playerscripts.com/images/mwap_graphics/MWAP_RT_STATS/nrg.png"><span id="user_energy"></span>
</tr>
<tr>
&nbsp;&nbsp;&nbsp;<img title="Current Stamina" src="http://www.playerscripts.com/images/mwap_graphics/MWAP_RT_STATS/stam.png"><span id="user_stamina"></span>
</tr>
</tr>




<tr id="Synch" style="display:none">
<td colspan="5" style="font-size:15px">
Click to synch with Zynga <a title="Synch" href="#" onclick="Synch()"><img src="http://www.playerscripts.com/images/mwap_graphics/MWAP_RT_STATS/synch.png" /></a>
</td>
</tr>
</table>
<font size="1"><div align="center">If unsure, simply hover over an icon.</div></font>
</body>
</html>
